/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************/
#include "ifinstructionlogic.h"

#include "GeneralDefine.h"
#include "programengine.h"
#include "messagelog.h"



IfInstructionLogic::IfInstructionLogic(int robotIdIn,ProgramSet* programSetIn,RobotIo* ioControllerIn
                                       ,ProgramEngine* programEngineIn)
{
    programSet=programSetIn;
    robotId=robotIdIn;
    ioController=ioControllerIn;
    programEngine=programEngineIn;

}

E_PROGRAM_LOOP_RESULT IfInstructionLogic::caseAnd(int programNum, IfInstruction andIfInstruction
                                , float runningLineFloat)
{
    //qDebug()<<"caseAnd&&&&&&&"<<__LINE__<<"andIfInstruction.condition.size()********"<<
    //           andIfInstruction.condition.size()<<endl;
    programEngine->updateProgramSetRegister();

    E_PROGRAM_LOOP_RESULT endFlag = E_PROGRAM_LOOP_RESULT_NORMAL;

    bool flag = true;
    double andVar,andValue;
    int tmpVar;

//    bool ioVar,ioValue;

    QVector <int> varPList;
    QVector <int> valPList;
    varPList.clear();
    valPList.clear();
    varPList.resize(3);
    valPList.resize(3);

    bool plFlag = false;
    for(int j = 0; j < andIfInstruction.condition.size();j++)
    {
        plFlag = false;
        switch(andIfInstruction.condition.at(j).variableType)
        {
            case IF_R:
            {
                //qDebug()<<"caseAnd&&&&&&&"<<__LINE__<<"*********andIfInstruction.condition.at(j).variable_i*********"<<
                //                        andIfInstruction.condition.at(j).variable_i<<"programSet->r.size()&&&&&&"<<
                //                       programSet->r.size()<<"***programSet->size()******"<<programSet->size()<<endl;
                switch(andIfInstruction.condition[j].front_addType)
                {
                case INDIRECT:
                {
                    if((D_ROBOT_REG_SIZE < andIfInstruction.condition[j].variable_i) || (D_ROBOT_REG_SIZE < programSet->regRList[andIfInstruction.condition[j].variable_i - 1])
                            ||(1 > andIfInstruction.condition[j].variable_i) || (1 > programSet->regRList[andIfInstruction.condition[j].variable_i - 1]))
                    {
                        programEngine->cmdError(programNum);
                        addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                        return E_PROGRAM_LOOP_RESULT_ERROR;
                    }
                    else
                    {
                        andVar = programSet->regRList[programSet->regRList[andIfInstruction.condition[j].variable_i - 1] - 1];
                    }
                    break;
                }
                case DIRECT:
                {
                    if(D_ROBOT_REG_SIZE < andIfInstruction.condition[j].variable_i || 1 > andIfInstruction.condition[j].variable_i)
                    {
                        programEngine->cmdError(programNum);
                        addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                        return E_PROGRAM_LOOP_RESULT_ERROR;
                    }
                    else
                    {
                        andVar = programSet->regRList[andIfInstruction.condition[j].variable_i - 1];
                    }
                    break;
                }
                }
                break;
            }
            case IF_AO:
            {
                break;
            }
            case IF_AI:
            {
                break;
            }
            case IF_GO:
            {
                break;
            }
            case IF_GI:
            {
                break;
            }
            case IF_DO:
            {
                switch(andIfInstruction.condition[j].front_addType)
                {
                    case INDIRECT:
                    {

                    }
                    break;
                    case DIRECT:
                    {
                        tmpVar = andIfInstruction.condition[j].variable_i - 1;
                    }
                    break;

                }
                if( ioController->doCount > tmpVar )
                {
//                    if(ioController->lock())
//                    {
                        andVar = ioController->ioDo[tmpVar];
//                        ioController->unlock();
//                    }
//                    else
//                    {
//                        qDebug()<<"io 映射錯誤 ！";
//                    }
                }
                else
                {
                    //                QString msg=QObject::tr( "IO毫超出已有逻辑ＩＯ范围，请检查指令或ＩＯ配置，: %1   ").arg( ioController->doCount );
    //                MessageLog::getInstance()->addMessage( ENUM_MSG_ERROR,  "ProgramEngine", "ProgramEngine",  3005,  robotId ,  0, 0, 0  );

                    addMsg( ENUM_MSG_ERROR, "ProgramEngine", "ProgramEngine",  3005, robotId
                            ,tmpVar, ioController->doCount,(*programSet)[programNum].runningLineInt,0,(*programSet)[programNum].thisProgramName);
                    programEngine->cmdError(programNum);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                break;
            }
            case IF_DI:
            {
                switch(andIfInstruction.condition[j].front_addType)
                {
                    case INDIRECT:
                    {

                    }
                    break;
                    case DIRECT:
                    {
                        tmpVar = andIfInstruction.condition[j].variable_i - 1;
                    }
                    break;

                }
                if( ioController->diCount > tmpVar )
                {
//                    if(ioController->lock())
//                    {
                        andVar = ioController->ioDi[tmpVar];
//                        ioController->unlock();
//                    }
//                    else
//                    {
//                        qDebug()<<"io 映射錯誤 ！";
//                    }
                }
                else
                {
                    //                QString msg=QObject::tr( "IO毫超出已有逻辑ＩＯ范围，请检查指令或ＩＯ配置，: %1   ").arg( ioController->doCount );
    //                MessageLog::getInstance()->addMessage( ENUM_MSG_ERROR,  "ProgramEngine", "ProgramEngine",  3005,  robotId ,  0, 0, 0  );

                    addMsg( ENUM_MSG_ERROR, "ProgramEngine", "ProgramEngine",  3005, robotId
                            ,tmpVar, ioController->diCount,(*programSet)[programNum].runningLineInt,0,(*programSet)[programNum].thisProgramName);
                    programEngine->cmdError(programNum);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                break;
            }
            case IF_RO:
            {
                break;
            }
            case IF_RI:
            {
                break;
            }
            case IF_SO:
            {
                break;
            }
            case IF_SI:
            {
                break;
            }
            case IF_UO:
            {
                break;
            }
            case IF_UI:
            {
                break;
            }
            case IF_PL:
            {
                plFlag = true;
                switch(andIfInstruction.condition[j].front_addType)
                {
                    case INDIRECT:
                    {
                        if((D_ROBOT_REG_SIZE < andIfInstruction.condition[j].variable_i) || (PL_SIZE < programSet->regRList[andIfInstruction.condition[j].variable_i - 1])
                                ||( 1 > andIfInstruction.condition[j].variable_i) || (1 > programSet->regRList[andIfInstruction.condition[j].variable_i - 1]))
                        {
                            programEngine->cmdError(programNum);
                            addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                            return E_PROGRAM_LOOP_RESULT_ERROR;
                        }
                        else
                        {
                            int num = programSet->regRList[andIfInstruction.condition[j].variable_i - 1] -1;
                            plRegStruct2List(num);
                            varPList = programSet->plList[num];
                        }
                        break;
                    }
                    case DIRECT:
                    {
                        if(PL_SIZE < andIfInstruction.condition[j].variable_i || 1 > andIfInstruction.condition[j].variable_i)
                        {
                            programEngine->cmdError(programNum);
                            addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                            return E_PROGRAM_LOOP_RESULT_ERROR;
                        }
                        else
                        {
                            int num = andIfInstruction.condition[j].variable_i - 1;
                            plRegStruct2List(num);
                            varPList = programSet->plList[num];
                        }
                        break;
                    }
                }
                break;
            }
            case IF_TIMER:
            {
//                int front_val;
                switch(andIfInstruction.condition[j].front_addType)
                {
                    case INDIRECT:
                    {
                        if(andIfInstruction.condition[j].variable_i >= 1 && andIfInstruction.condition[j].variable_i <= programSet->regRList.size())
                        {
                            andVar = (int)programSet->regRList[andIfInstruction.condition[j].variable_i - 1];
                        }
                        else
                        {
                            programEngine->cmdError(programNum);
                            addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                            return E_PROGRAM_LOOP_RESULT_ERROR;
                        }
                        break;
                    }
                    case DIRECT:
                    {
                        andVar = andIfInstruction.condition[j].variable_i - 1;
                        break;
                    }
                }
                break;
            }
        }
        switch(andIfInstruction.condition.at(j).valueType)
        {
        case IF_R:
        {
            switch(andIfInstruction.condition[j].back_addType)
            {
                case INDIRECT:
                {
                    if((D_ROBOT_REG_SIZE < andIfInstruction.condition[j].value_i) || (D_ROBOT_REG_SIZE < programSet->regRList[andIfInstruction.condition[j].value_i - 1])
                            ||(1 > andIfInstruction.condition[j].value_i) || (1 > programSet->regRList[andIfInstruction.condition[j].value_i -1]))
                    {
                        programEngine->cmdError(programNum);
                        addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                        return E_PROGRAM_LOOP_RESULT_ERROR;
                    }
                    else
                    {
                        andValue = programSet->regRList[programSet->regRList[andIfInstruction.condition[j].value_i -1] -1];
                    }
                    break;
                }
                case DIRECT:
                {
                    if(D_ROBOT_REG_SIZE < andIfInstruction.condition[j].value_i || 1 > andIfInstruction.condition[j].value_i)
                    {
                        programEngine->cmdError(programNum);
                        addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                        return E_PROGRAM_LOOP_RESULT_ERROR;
                    }
                    else
                    {
                        andValue = programSet->regRList[andIfInstruction.condition[j].value_i - 1];
                    }
                    //qDebug()<<"caseAnd&&&&&&&"<<__LINE__<<"*********andIfInstruction.condition.at(j).variable_i*********"<<
                    //                        andIfInstruction.condition.at(j).variable_i<<"*********andVar**********"<<andVar<<endl;
                    break;
                }
            }
            break;
        }
        case IF_AO:
        {
            break;
        }
        case IF_AI:
        {
            break;
        }
        case IF_GO:
        {
            break;
        }
        case IF_GI:
        {
            break;
        }
        case IF_DO:
        {
            break;
        }
        case IF_DI:
        {
            break;
        }
        case IF_RO:
        {
            break;
        }
        case IF_RI:
        {
            break;
        }
        case IF_SO:
        {
            break;
        }
        case IF_SI:
        {
            break;
        }
        case IF_UO:
        {
            break;
        }
        case IF_UI:
        {
            break;
        }
        case IF_ON:
        {
            andValue = 1;
            break;
        }
        case IF_OFF:
        {
            andValue = 0;
            break;
        }
        case IF_PL:
        {
            switch(andIfInstruction.condition[j].back_addType)
            {
                case INDIRECT:
                {
                    if((D_ROBOT_REG_SIZE < andIfInstruction.condition[j].value_i) || (PL_SIZE < programSet->regRList[andIfInstruction.condition[j].value_i - 1])
                            ||(1 > andIfInstruction.condition[j].value_i ) ||( 1 > programSet->regRList[andIfInstruction.condition[j].value_i - 1]))
                    {
                        programEngine->cmdError(programNum);
                        addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                        return E_PROGRAM_LOOP_RESULT_ERROR;
                    }
                    else
                    {
                        int num = programSet->regRList[andIfInstruction.condition[j].value_i - 1] - 1;
                        plRegStruct2List(num);
                        valPList = programSet->plList[num];
                    }
                    break;
                }
                case DIRECT:
                {
                    if(PL_SIZE < andIfInstruction.condition[j].value_i || 1 > andIfInstruction.condition[j].value_i)
                    {
                        programEngine->cmdError(programNum);
                        addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                        return E_PROGRAM_LOOP_RESULT_ERROR;
                    }
                    else
                    {
                        int num = andIfInstruction.condition[j].value_i - 1;
                        plRegStruct2List(num);
                        valPList = programSet->plList[num];
                    }
                    break;
                }
            }
            break;
        }
        case IF_PL_IJK:
        {
            if(INDIRECT == andIfInstruction.condition[j].i_addType)
            {
                if(D_ROBOT_REG_SIZE < andIfInstruction.condition[j].pl_i || 1 > andIfInstruction.condition[j].pl_i)
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    valPList[0] = programSet->regRList[andIfInstruction.condition[j].pl_i - 1];
                }
            }
            else if(DIRECT == andIfInstruction.condition[j].i_addType)
            {
                    valPList[0] = andIfInstruction.condition[j].pl_i;
            }
            if(INDIRECT == andIfInstruction.condition[j].j_addType)
            {
                if(D_ROBOT_REG_SIZE < andIfInstruction.condition[j].pl_j || 1 > andIfInstruction.condition[j].pl_j)
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    valPList[1] = programSet->regRList[andIfInstruction.condition[j].pl_j - 1];
                }
            }
            else if(DIRECT == andIfInstruction.condition[j].j_addType)
            {
                valPList[1] = andIfInstruction.condition[j].pl_j;
            }
            if(INDIRECT == andIfInstruction.condition[j].k_addType)
            {
                if(D_ROBOT_REG_SIZE < andIfInstruction.condition[j].pl_k || 0 > andIfInstruction.condition[j].pl_k)
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    valPList[2] = programSet->regRList[andIfInstruction.condition[j].pl_k - 1];
                }
            }
            else if(DIRECT == andIfInstruction.condition[j].k_addType)
            {
                valPList[2] = andIfInstruction.condition[j].pl_k;
            }
            break;
        }
        case IF_CONST:
        {
            andValue = andIfInstruction.condition[j].value_i;
            break;
        }
        }
        switch (andIfInstruction.condition.at(j).operatorType)
        {
        case GREATER:
        {
            if(andVar <= andValue)
            {
                flag = false;
            }
            break;
        }
        case GREATER_EQU:
        {
            if(andVar < andValue)
            {
                flag = false;
            }
            if(D_POSITIVE_ZERO>andVar && D_NEGATIVE_ZERO<andVar &&
                    D_POSITIVE_ZERO>andValue && D_NEGATIVE_ZERO<andValue)// in case of 0.00000000001
            {
                flag = false;
            }

            break;
        }
        case EQU:
        {
            if(true == plFlag)
            {
                for(int i = 0; i < 3;i++)
                {
                    if((varPList[i] > 500) && (varPList[i] < 10000))
                    {
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            varPList[i] = valPList[i];
                        }
                        if((0 == varPList[i] % 2) && (0 == valPList[i] % 2))
                        {
                            varPList[i] = valPList[i];
                        }
                    }
                    if((varPList[i] > 10000))
                    {
                        varPList[i] = valPList[i];
                    }

                    if((valPList[i] > 500) && (valPList[i] < 10000))
                    {
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            valPList[i] = varPList[i];
                        }
                        if((0 == varPList[i] % 2) && (0 == valPList[i] % 2))
                        {
                            valPList[i] = varPList[i];
                        }
                    }
                    if((valPList[i] > 10000))
                    {
                        valPList[i] = varPList[i];
                    }
                }
                if(varPList != valPList)
                {
                    flag = false;
                }
            }
            else
            {
                if(andVar != andValue)
                {
                    flag = false;
                }
            }
            break;
        }
        case SMALLER_EQU:
        {
            if(andVar >= andValue)
            {
                flag = false;
            }
            if(D_POSITIVE_ZERO>andVar && D_NEGATIVE_ZERO<andVar &&
                    D_POSITIVE_ZERO>andValue && D_NEGATIVE_ZERO<andValue)// in case of 0.00000000001
            {
                flag = false;
            }
            break;
        }
        case SMALLER:
        {
            if(andVar > andValue)
            {
                flag = false;
            }
            break;
        }
        case NOT_EQU:
        {
            if(true == plFlag)
            {
                for(int i = 0; i < 3;i++)
                {
                    if((varPList[i] > 500) && (varPList[i] < 10000))
                    {
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            varPList[i] = valPList[i];
                        }
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            varPList[i] = valPList[i];
                        }
                    }
                    if((varPList[i] > 10000))
                    {
                        varPList[i] = valPList[i];
                    }

                    if((valPList[i] > 500) && (valPList[i] < 10000))
                    {
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            valPList[i] = varPList[i];
                        }
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            valPList[i] = varPList[i];
                        }
                    }
                    if((valPList[i] > 10000))
                    {
                        valPList[i] = varPList[i];
                    }
                }
                if(varPList == valPList)
                {
                    flag = false;
                }
            }
            else
            {
                if(andVar == andValue)
                {
                    flag = false;
                }
                if(D_POSITIVE_ZERO>andVar && D_NEGATIVE_ZERO<andVar &&
                        D_POSITIVE_ZERO>andValue && D_NEGATIVE_ZERO<andValue)// in case of 0.00000000001
                {
                    flag = false;
                }
            }
            break;
        }
        }
        if(flag == false)
        {
            break;
        }
        else
        {
            continue;
        }
    }

    if(flag == false)
    {
        programEngine->calculateNextLineToRun(programNum);

        //qDebug()<<"caseAnd&&&&&&ORDER_SERIES_STATE&&&&&&"<<__LINE__<<
        //                  "+++++startIfAdd********programSet->pc"<<programSet[programNum].pc<<
        //                  "programNum***********"<<programNum<<endl;
    }
    else
    {
        if(programNum >= programSet->size())
        {
            return E_PROGRAM_LOOP_RESULT_ERROR;
        }
        else if(0==(*programSet)[programNum].size() )
        {
            qDebug()<<"caseAnd jump call error2,0==(*programSet)[programNum].size ";
            return E_PROGRAM_LOOP_RESULT_ERROR;
        }

        switch(andIfInstruction.processType)
        {
        case JMP:
        {
            //                qDebug()<<"caseAnd&&&&&&ORDER_SERIES_STATE&&&&&&"<<__LINE__<<
            //                          "+++++startIfAdd********programSet->pc"<<programSet[programNum].pc<<
            //                          "programNum***********"<<programNum<<endl;
            QString tmpjumpLabel=(*programSet)[programNum].at(runningLineFloat).ifIns.jumpProcess.jumpLabelStr;
            programEngine->startJump(programNum,tmpjumpLabel);
            break;
        }
        case CALLING:
        {

            programEngine->startCall(programNum,(*programSet)[programNum].at(runningLineFloat).ifIns.callProcess.programName);
//            for(int k = 0; k < programSet->size();k++)
//            {
//                if(programSet[programNum].at(pCount).ifIns.callProcess.programName == programSet[k].programName)
//                {
//                    //qDebug()<<"caseAnd&&&&&&ORDER_SERIES_STATE&&&&&&"<<__LINE__<<
//                    //                                  "+++++startIfAdd********programSet->pc"<<programSet[programNum].pc<<
//                    //                                  "programNum***********"<<programNum<<endl;
//                    //                        startCall(programNum,k);
//                    break;
//                }
//            }
            break;
        }
        }
    }

    endFlag = programEngine->isTheLastInstruction(programNum);

    return endFlag;
}

E_PROGRAM_LOOP_RESULT IfInstructionLogic::caseOr(int programNum, IfInstruction orIfInstruction
                               , float runningLineFloat)
{
    programEngine->updateProgramSetRegister();

    E_PROGRAM_LOOP_RESULT endFlag = E_PROGRAM_LOOP_RESULT_NORMAL;

    QVector <int> varPList;
    QVector <int> valPList;
    varPList.clear();
    valPList.clear();
    varPList.resize(3);
    valPList.resize(3);

    bool plFlag = false;

    bool flag = false;
    double andVar,andValue;
    int tmpVar;

    for(int j = 0; j < orIfInstruction.condition.size();j++)
    {
        plFlag = false;
        switch(orIfInstruction.condition.at(j).variableType)
        {
        case IF_R:
        {
            switch(orIfInstruction.condition[j].front_addType)
            {
            case INDIRECT:
            {
                if((D_ROBOT_REG_SIZE < orIfInstruction.condition[j].variable_i) || (D_ROBOT_REG_SIZE < programSet->regRList[orIfInstruction.condition[j].variable_i - 1])
                        ||(1 > orIfInstruction.condition[j].variable_i) || (1 > programSet->regRList[orIfInstruction.condition[j].variable_i - 1]))
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    andVar = programSet->regRList[programSet->regRList[orIfInstruction.condition[j].variable_i - 1] -1];
                }
                break;
            }
            case DIRECT:
            {
                if((D_ROBOT_REG_SIZE < orIfInstruction.condition[j].variable_i) || (1 > orIfInstruction.condition[j].variable_i))
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    andVar = programSet->regRList[orIfInstruction.condition[j].variable_i - 1];
                }
                break;
            }
            }
            break;
        }
        case IF_AO:
        {
            break;
        }
        case IF_AI:
        {
            break;
        }
        case IF_GO:
        {
            break;
        }
        case IF_GI:
        {
            break;
        }
        case IF_DO:
        {
            switch(orIfInstruction.condition[j].front_addType)
            {
                case INDIRECT:
                {

                }
                break;
                case DIRECT:
                {
                    tmpVar = orIfInstruction.condition[j].variable_i - 1;
                }
                break;

            }
            if( ioController->doCount > tmpVar )
            {
//                if(ioController->lock())
//                {
                    andVar = ioController->ioDo[tmpVar];
//                    ioController->unlock();
//                }
//                else
//                {
//                    qDebug()<<"io 映射錯誤 ！";
//                }
            }
            else
            {
                //                QString msg=QObject::tr( "IO毫超出已有逻辑ＩＯ范围，请检查指令或ＩＯ配置，: %1   ").arg( ioController->doCount );
//                MessageLog::getInstance()->addMessage( ENUM_MSG_ERROR,  "ProgramEngine", "ProgramEngine",  3005,  robotId ,  0, 0, 0  );

                addMsg( ENUM_MSG_ERROR, "ProgramEngine", "ProgramEngine",  3005, robotId ,tmpVar, ioController->doCount,(*programSet)[programNum].runningLineInt,0,(*programSet)[programNum].thisProgramName);
                programEngine->cmdError(programNum);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            break;
        }
        case IF_DI:
        {
            switch(orIfInstruction.condition[j].front_addType)
            {
                case INDIRECT:
                {

                }
                break;
                case DIRECT:
                {
                    tmpVar = orIfInstruction.condition[j].variable_i - 1;
                }
                break;

            }
            if( ioController->diCount > tmpVar )
            {
//                if(ioController->lock())
//                {
                    andVar = ioController->ioDi[tmpVar];
//                    ioController->unlock();
//                }
//                else
//                {
//                    qDebug()<<"io 映射錯誤 ！";
//                }
            }
            else
            {
                //                QString msg=QObject::tr( "IO毫超出已有逻辑ＩＯ范围，请检查指令或ＩＯ配置，: %1   ").arg( ioController->doCount );
//                MessageLog::getInstance()->addMessage( ENUM_MSG_ERROR,  "ProgramEngine", "ProgramEngine",  3005,  robotId ,  0, 0, 0  );

                addMsg( ENUM_MSG_ERROR, "ProgramEngine", "ProgramEngine",  3005, robotId ,tmpVar, ioController->diCount,(*programSet)[programNum].runningLineInt,0,(*programSet)[programNum].thisProgramName);
                programEngine->cmdError(programNum);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            break;
        }
        case IF_RO:
        {
            break;
        }
        case IF_RI:
        {
            break;
        }
        case IF_SO:
        {
            break;
        }
        case IF_SI:
        {
            break;
        }
        case IF_UO:
        {
            break;
        }
        case IF_UI:
        {
            break;
        }
        case IF_PL:
        {
            plFlag = true;
            switch(orIfInstruction.condition[j].front_addType)
            {
            case INDIRECT:
            {
                if((D_ROBOT_REG_SIZE < orIfInstruction.condition[j].variable_i) || (PL_SIZE < programSet->regRList[orIfInstruction.condition[j].variable_i - 1])
                        ||(1 > orIfInstruction.condition[j].variable_i) || (1 > programSet->regRList[orIfInstruction.condition[j].variable_i - 1]))
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    int num = programSet->regRList[orIfInstruction.condition[j].variable_i - 1] - 1;
                    plRegStruct2List(num);
                    varPList = programSet->plList[num];
                }
                break;
            }
            case DIRECT:
            {
                if(PL_SIZE < orIfInstruction.condition[j].variable_i || 1 > orIfInstruction.condition[j].variable_i )
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    int num = orIfInstruction.condition[j].variable_i - 1;
                    plRegStruct2List(num);
                    varPList = programSet->plList[num];
                }
                break;
            }
            }
            break;
        }
        case IF_TIMER:
        {
//                int front_val;
            switch(orIfInstruction.condition[j].front_addType)
            {
                case INDIRECT:
                {
                    if(orIfInstruction.condition[j].variable_i >= 1 && orIfInstruction.condition[j].variable_i <= programSet->regRList.size())
                    {
                        andVar = (int)programSet->regRList[orIfInstruction.condition[j].variable_i - 1];
                    }
                    else
                    {
                        programEngine->cmdError(programNum);
                        addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                        return E_PROGRAM_LOOP_RESULT_ERROR;
                    }
                    break;
                }
                case DIRECT:
                {
                    andVar = orIfInstruction.condition[j].variable_i - 1;
                    break;
                }
            }
            break;
        }
        }
        switch(orIfInstruction.condition.at(j).valueType)
        {
        case IF_R:
        {
            switch(orIfInstruction.condition[j].back_addType)
            {
            case INDIRECT:
            {
                if((D_ROBOT_REG_SIZE < orIfInstruction.condition[j].value_i) || (D_ROBOT_REG_SIZE < programSet->regRList[orIfInstruction.condition[j].value_i - 1])
                        ||(1 > orIfInstruction.condition[j].value_i ) || (1 > programSet->regRList[orIfInstruction.condition[j].value_i - 1]))
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    andValue = programSet->regRList[programSet->regRList[orIfInstruction.condition[j].value_i - 1] -1];
                }
                break;
            }
            case DIRECT:
            {
                if(D_ROBOT_REG_SIZE < orIfInstruction.condition[j].value_i && 1 > orIfInstruction.condition[j].value_i)
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    andValue = programSet->regRList[orIfInstruction.condition[j].value_i - 1];
                }
                //qDebug()<<"caseAnd&&&&&&&"<<__LINE__<<"*********andIfInstruction.condition.at(j).variable_i*********"<<
                //                        andIfInstruction.condition.at(j).variable_i<<"*********andVar**********"<<andVar<<endl;
                break;
            }
            }
            break;
        }
        case IF_AO:
        {
            break;
        }
        case IF_AI:
        {
            break;
        }
        case IF_GO:
        {
            break;
        }
        case IF_GI:
        {
            break;
        }
        case IF_DO:
        {
            break;
        }
        case IF_DI:
        {
            break;
        }
        case IF_RO:
        {
            break;
        }
        case IF_RI:
        {
            break;
        }
        case IF_SO:
        {
            break;
        }
        case IF_SI:
        {
            break;
        }
        case IF_UO:
        {
            break;
        }
        case IF_UI:
        {
            break;
        }
        case IF_ON:
        {
            andValue = 1;
            break;
        }
        case IF_OFF:
        {
            andValue = 0;
            break;
        }
        case IF_PL:
        {
            switch(orIfInstruction.condition[j].back_addType)
            {
            case INDIRECT:
            {
                if((D_ROBOT_REG_SIZE < orIfInstruction.condition[j].value_i) || (PL_SIZE < programSet->regRList[orIfInstruction.condition[j].value_i - 1])
                        ||(1 > orIfInstruction.condition[j].value_i) ||(1 > programSet->regRList[orIfInstruction.condition[j].value_i - 1]))
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    int num = programSet->regRList[orIfInstruction.condition[j].value_i - 1] -1;
                    plRegStruct2List(num);
                    valPList = programSet->plList[num];
                }
                break;
            }
            case DIRECT:
            {
                if((D_ROBOT_REG_SIZE < orIfInstruction.condition[j].value_i) || (1 > orIfInstruction.condition[j].value_i))
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    int num = orIfInstruction.condition[j].value_i -1;
                    plRegStruct2List(num);
                    valPList = programSet->plList[num];
                }
                break;
            }
            }
            break;
        }
        case IF_PL_IJK:
        {
            if(INDIRECT == orIfInstruction.condition[j].i_addType)
            {
                if(D_ROBOT_REG_SIZE < orIfInstruction.condition[j].pl_i || 1 > orIfInstruction.condition[j].pl_i)
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    valPList[0] = programSet->regRList[orIfInstruction.condition[j].pl_i - 1];
                }
            }
            else if(DIRECT == orIfInstruction.condition[j].i_addType)
            {
                valPList[0] = orIfInstruction.condition[j].pl_i;
            }
            if(INDIRECT == orIfInstruction.condition[j].j_addType)
            {
                if(D_ROBOT_REG_SIZE < orIfInstruction.condition[j].pl_j || 1 > orIfInstruction.condition[j].pl_j)
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    valPList[1] = programSet->regRList[orIfInstruction.condition[j].pl_j -1];
                }
            }
            else if(DIRECT == orIfInstruction.condition[j].j_addType)
            {
                valPList[1] = orIfInstruction.condition[j].pl_j;
            }
            if(INDIRECT == orIfInstruction.condition[j].k_addType)
            {
                if(D_ROBOT_REG_SIZE < orIfInstruction.condition[j].pl_k || 1 > orIfInstruction.condition[j].pl_k)
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                else
                {
                    valPList[2] = programSet->regRList[orIfInstruction.condition[j].pl_k -1];
                }
            }
            else if(DIRECT == orIfInstruction.condition[j].k_addType)
            {
                valPList[2] = orIfInstruction.condition[j].pl_k;
            }
            break;
        }
        case IF_CONST:
        {
            andValue = orIfInstruction.condition[j].value_i;
            break;
        }
        }
        switch (orIfInstruction.condition.at(j).operatorType)
        {
        case GREATER:
        {
            if(andVar > andValue)
            {
                flag = true;
            }
            break;
        }
        case GREATER_EQU:
        {
            if(andVar >= andValue)
            {
                flag = true;
            }
            if(D_POSITIVE_ZERO>andVar && D_NEGATIVE_ZERO<andVar &&
                    D_POSITIVE_ZERO>andValue && D_NEGATIVE_ZERO<andValue)// in case of 0.00000000001
            {
                flag = true;
            }
            break;
        }
        case EQU:
        {
            if(true == plFlag)
            {
                for(int i = 0; i < 3;i++)
                {
                    if((varPList[i] > 500) && (varPList[i] < 10000))
                    {
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            varPList[i] = valPList[i];
                        }
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            varPList[i] = valPList[i];
                        }
                    }
                    if((varPList[i] > 10000))
                    {
                        varPList[i] = valPList[i];
                    }

                    if((valPList[i] > 500) && (valPList[i] < 10000))
                    {
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            valPList[i] = varPList[i];
                        }
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            valPList[i] = varPList[i];
                        }
                    }
                    if((valPList[i] > 10000))
                    {
                        valPList[i] = varPList[i];
                    }
                }
                if(varPList == valPList)
                {
                    flag = true;
                }
            }
            else
            {
                if(andVar == andValue)
                {
                    flag = true;
                }
                if(D_POSITIVE_ZERO>andVar && D_NEGATIVE_ZERO<andVar &&
                        D_POSITIVE_ZERO>andValue && D_NEGATIVE_ZERO<andValue)// in case of 0.00000000001
                {
                    flag = true;
                }

            }
            break;
        }
        case SMALLER_EQU:
        {
            if(andVar <= andValue)
            {
                flag = true;
            }
            if(D_POSITIVE_ZERO>andVar && D_NEGATIVE_ZERO<andVar &&
                    D_POSITIVE_ZERO>andValue && D_NEGATIVE_ZERO<andValue)// in case of 0.00000000001
            {
                flag = true;
            }
            break;
        }
        case SMALLER:
        {
            if(andVar < andValue)
            {
                flag = true;
            }
            break;
        }
        case NOT_EQU:
        {
            if(true == plFlag)
            {
                for(int i = 0; i < 3;i++)
                {
                    if((varPList[i] > 500) && (varPList[i] < 10000))
                    {
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            varPList[i] = valPList[i];
                        }
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            varPList[i] = valPList[i];
                        }
                    }
                    if((varPList[i] > 10000))
                    {
                        varPList[i] = valPList[i];
                    }

                    if((valPList[i] > 500) && (valPList[i] < 10000))
                    {
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            valPList[i] = varPList[i];
                        }
                        if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                        {
                            valPList[i] = varPList[i];
                        }
                    }
                    if((valPList[i] > 10000))
                    {
                        valPList[i] = varPList[i];
                    }
                }
                if(varPList != valPList)
                {
                    flag = true;
                }
            }
            else
            {
                if(andVar != andValue)
                {
                    flag = true;
                }
            }
            break;
        }
        }

        if(flag == true)
        {
            break;
        }
        else
        {
            continue;
        }
    }

    if(flag == false)
    {
        programEngine->calculateNextLineToRun(programNum);

    }
    else
    {
        if(programNum >= programSet->size())
        {
            return E_PROGRAM_LOOP_RESULT_ERROR;
        }
        else if(0==(*programSet)[programNum].size() )
        {
            qDebug()<<"caseOr jump call error2,0==(*programSet)[programNum].size ";
            return E_PROGRAM_LOOP_RESULT_ERROR;
        }

        switch(orIfInstruction.processType)
        {
        case JMP:
        {
            //                qDebug()<<__FUNCTION__<<"**LINE***"<<__LINE__<<endl;
            QString tmpjumpLabel=(*programSet)[programNum].at(runningLineFloat).ifIns.jumpProcess.jumpLabelStr;
            programEngine->startJump(programNum,tmpjumpLabel);

            break;
        }
        case CALLING:
        {

            programEngine->startCall(programNum,(*programSet)[programNum].at(runningLineFloat).ifIns.callProcess.programName);
//            for(int k = 0; k < programSet->size();k++)
//            {
//                if(programSet[programNum].at(pCount).ifIns.callProcess.programName == programSet[k].programName)
//                {
//                    //                        startCall(programNum,k);
//                    break;
//                }
//            }
            break;
        }
        }
    }

    endFlag = programEngine->isTheLastInstruction(programNum);

    return endFlag;
}


E_PROGRAM_LOOP_RESULT IfInstructionLogic::caseNeither(int programNum, IfInstruction nIfInstruction
                                    , float runningLineFloat)
{
    programEngine->updateProgramSetRegister();
    E_PROGRAM_LOOP_RESULT endFlag = E_PROGRAM_LOOP_RESULT_NORMAL;

    QVector <int> varPList;
    QVector <int> valPList;
    varPList.clear();
    valPList.clear();
    varPList.resize(3);
    valPList.resize(3);

    bool plFlag = false;

    bool flag = false;
    double andVar,andValue;
    int tmpVar;

//    qDebug()<<"if variableType="<<nIfInstruction.condition.at(0).variableType;
    switch(nIfInstruction.condition.at(0).variableType)
    {
    case IF_R:
    {
        switch(nIfInstruction.condition[0].front_addType)
        {
        case INDIRECT:
        {
            if((D_ROBOT_REG_SIZE < nIfInstruction.condition[0].variable_i) || (D_ROBOT_REG_SIZE < programSet->regRList[nIfInstruction.condition[0].variable_i - 1])
                    ||(1 > nIfInstruction.condition[0].variable_i ) || (1 > programSet->regRList[nIfInstruction.condition[0].variable_i -1]))
            {
                programEngine->cmdError(programNum);
                addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            else
            {
                //andVar = programSet->r[programSet->r[nIfInstruction.condition[0].variable_i -1] -1];
                andVar = programSet->regRList[programSet->regRList[nIfInstruction.condition[0].variable_i -1] -1];
//                qDebug()<<"andVar = "<<andVar;
            }
            break;
        }
        case DIRECT:
        {
            if(D_ROBOT_REG_SIZE < nIfInstruction.condition[0].variable_i || 1 > nIfInstruction.condition[0].variable_i)
            {
                programEngine->cmdError(programNum);
                addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            else
            {
                //andVar = programSet->r[nIfInstruction.condition[0].variable_i - 1];
//                qDebug()<<"regRList index="<<nIfInstruction.condition[0].variable_i - 1
//                       <<" size"<<programSet->regRList.size();
                andVar = programSet->regRList[nIfInstruction.condition[0].variable_i - 1];
            }

//            qDebug()<<__FUNCTION__<<"*****"<<__LINE__<<"**var_i****"<<nIfInstruction.condition[0].variable_i<<
//                      "**r**"<<andVar<<endl;
            break;
        }
        }
        break;
    }
    case IF_AO:
    {
        break;
    }
    case IF_AI:
    {
        break;
    }
    case IF_GO:
    {
        break;
    }
    case IF_GI:
    {
        break;
    }
    case IF_DO:
    {
        switch(nIfInstruction.condition[0].front_addType)
        {
            case INDIRECT:
            {

            }
            break;
            case DIRECT:
            {
                tmpVar = nIfInstruction.condition[0].variable_i - 1;
            }
            break;
        }
//        qDebug() << "====after========"<<"\n\n";
       if( ioController->doCount > tmpVar )
       {
//           if(ioController->lock())
//           {
               andVar = ioController->ioDo[tmpVar];
//               qDebug() << "====andVar==="<<andVar<<"\n\n";
//               ioController->unlock();
//           }
//           else
//           {
//               qDebug()<<"io 映射錯誤 ！";
//           }
       }
       else
       {
           //                QString msg=QObject::tr( "IO毫超出已有逻辑ＩＯ范围，请检查指令或ＩＯ配置，: %1   ").arg( ioController->doCount );
//                MessageLog::getInstance()->addMessage( ENUM_MSG_ERROR,  "ProgramEngine", "ProgramEngine",  3005,  robotId ,  0, 0, 0  );

           addMsg( ENUM_MSG_ERROR, "ProgramEngine", "ProgramEngine",  3005, robotId ,tmpVar, ioController->doCount,(*programSet)[programNum].runningLineInt,0,(*programSet)[programNum].thisProgramName);
           programEngine->cmdError(programNum);
           return E_PROGRAM_LOOP_RESULT_ERROR;
       }
        break;
    }
    case IF_DI:
    {
        switch(nIfInstruction.condition[0].front_addType)
        {
            case INDIRECT:
            {

            }
            break;
            case DIRECT:
            {
                tmpVar = nIfInstruction.condition[0].variable_i - 1;
            }
            break;

        }
        if( ioController->diCount > tmpVar )
        {
//            if(ioController->lock())
//            {
                andVar = ioController->ioDi[tmpVar];
//                ioController->unlock();
//            }
//            else
//            {
//                qDebug()<<"io 映射錯誤 ！";
//            }
        }
        else
        {
            //                QString msg=QObject::tr( "IO毫超出已有逻辑ＩＯ范围，请检查指令或ＩＯ配置，: %1   ").arg( ioController->doCount );
//                MessageLog::getInstance()->addMessage( ENUM_MSG_ERROR,  "ProgramEngine", "ProgramEngine",  3005,  robotId ,  0, 0, 0  );

            addMsg( ENUM_MSG_ERROR, "ProgramEngine", "ProgramEngine",  3005, robotId ,tmpVar, ioController->diCount,(*programSet)[programNum].runningLineInt,0,(*programSet)[programNum].thisProgramName);
            programEngine->cmdError(programNum);
            return E_PROGRAM_LOOP_RESULT_ERROR;
        }
        break;
    }
    case IF_RO:
    {
        break;
    }
    case IF_RI:
    {
        break;
    }
    case IF_SO:
    {
        break;
    }
    case IF_SI:
    {
        break;
    }
    case IF_UO:
    {
        break;
    }
    case IF_UI:
    {
        break;
    }
    case IF_PL:
    {
        plFlag = true;
        switch(nIfInstruction.condition[0].front_addType)
        {
        case INDIRECT:
        {
            if((D_ROBOT_REG_SIZE < nIfInstruction.condition[0].variable_i) || (PL_SIZE < programSet->regRList[nIfInstruction.condition[0].variable_i - 1])
                    ||(1 > nIfInstruction.condition[0].variable_i) || (1 > programSet->regRList[nIfInstruction.condition[0].variable_i -1]))
            {
                programEngine->cmdError(programNum);
                addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            else
            {
                int num = programSet->regRList[nIfInstruction.condition[0].variable_i -1] -1;
                plRegStruct2List(num);
                varPList = programSet->plList[num];
            }
            break;
        }
        case DIRECT:
        {
            if(PL_SIZE < nIfInstruction.condition[0].variable_i || 1 > nIfInstruction.condition[0].variable_i)
            {
                programEngine->cmdError(programNum);
                addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            else
            {
                int num = nIfInstruction.condition[0].variable_i -1;
                plRegStruct2List(num);
                varPList = programSet->plList[num];
//                qDebug() << "====variable_i==="<<nIfInstruction.condition[0].variable_i<<"***varPList***"<<varPList;
            }
            break;
        }
        }
        break;
    }
    case IF_TIMER:
    {
//                int front_val;
        switch(nIfInstruction.condition[0].front_addType)
        {
            case INDIRECT:
            {
                if(nIfInstruction.condition[0].variable_i >= 1 && nIfInstruction.condition[0].variable_i <= programSet->regRList.size())
                {
                    andVar = (int)programSet->regRList[nIfInstruction.condition[0].variable_i - 1];
                }
                else
                {
                    programEngine->cmdError(programNum);
                    addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                    return E_PROGRAM_LOOP_RESULT_ERROR;
                }
                break;
            }
            case DIRECT:
            {
                andVar = nIfInstruction.condition[0].variable_i - 1;
//                qDebug() << "====variable_i==="<<nIfInstruction.condition[0].variable_i<<"===andVar==="<<andVar;
                break;
            }
        }
        if(andVar >=0 && andVar < programSet->countTimer.size())
        {
            andVar = programSet->countTimer[andVar];
        }
        else
        {
            programEngine->cmdError(programNum);
            addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
            return E_PROGRAM_LOOP_RESULT_ERROR;
        }
        break;
    }
    }

//   qDebug() << "===valueType====="<<nIfInstruction.condition.at(0).valueType;
//    qDebug() << "nIfInstruction.condition.at(0).valueType＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝"<<
//                nIfInstruction.condition.at(0).valueType;
//    qDebug()<<"if valueType="<<nIfInstruction.condition.at(0).valueType;
    switch(nIfInstruction.condition.at(0).valueType)
    {

    case IF_R:
    {
        switch(nIfInstruction.condition[0].back_addType)
        {
        case INDIRECT:
        {
            if((D_ROBOT_REG_SIZE < nIfInstruction.condition[0].value_i) || (D_ROBOT_REG_SIZE < programSet->regRList[nIfInstruction.condition[0].value_i - 1])
                    ||(1 >nIfInstruction.condition[0].value_i) ||(1 > programSet->regRList[nIfInstruction.condition[0].value_i - 1]))
            {
                programEngine->cmdError(programNum);
                addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            else
            {
                andValue = programSet->regRList[programSet->regRList[nIfInstruction.condition[0].value_i - 1] -1];
            }
            break;
        }
        case DIRECT:
        {
            if(D_ROBOT_REG_SIZE < nIfInstruction.condition[0].value_i || 1 > nIfInstruction.condition[0].value_i)
            {
                programEngine->cmdError(programNum);
                addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            else
            {
                andValue = programSet->regRList[nIfInstruction.condition[0].value_i - 1];
            }
            //qDebug()<<"caseAnd&&&&&&&"<<__LINE__<<"*********andIfInstruction.condition.at(j).variable_i*********"<<
            //                        andIfInstruction.condition.at(j).variable_i<<"*********andVar**********"<<andVar<<endl;
            break;
        }
        }
        break;
    }
    case IF_AO:
    {
        break;
    }
    case IF_AI:
    {
        break;
    }
    case IF_GO:
    {
        break;
    }
    case IF_GI:
    {
        break;
    }
    case IF_DO:
    {
        break;
    }
    case IF_DI:
    {
        break;
    }
    case IF_RO:
    {
        break;
    }
    case IF_RI:
    {
        break;
    }
    case IF_SO:
    {
        break;
    }
    case IF_SI:
    {
        break;
    }
    case IF_UO:
    {
        break;
    }
    case IF_UI:
    {
        break;
    }
    case IF_ON:
    {
        andValue = 1;
        break;
    }
    case IF_OFF:
    {
        andValue = 0;
        break;
    }
    case IF_PL:
    {
        switch(nIfInstruction.condition[0].back_addType)
        {
        case INDIRECT:
        {
            if((D_ROBOT_REG_SIZE < nIfInstruction.condition[0].value_i) || (PL_SIZE < programSet->regRList[nIfInstruction.condition[0].value_i - 1])
                    ||(1 > nIfInstruction.condition[0].value_i) ||(1 > programSet->regRList[nIfInstruction.condition[0].value_i - 1]))
            {
                programEngine->cmdError(programNum);
                addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            else
            {
                int num = programSet->regRList[nIfInstruction.condition[0].value_i - 1] -1;
                plRegStruct2List(num);
                valPList = programSet->plList[num];
            }
            break;
        }
        case DIRECT:
        {
            if(PL_SIZE < nIfInstruction.condition[0].value_i || 1 > nIfInstruction.condition[0].value_i)
            {
                programEngine->cmdError(programNum);
                addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            else
            {
                int num = nIfInstruction.condition[0].value_i - 1;
                plRegStruct2List(num);
                valPList = programSet->plList[num];
            }
            break;
        }
        }
        break;
    }
    case IF_PL_IJK:
    {
        if(INDIRECT == nIfInstruction.condition[0].i_addType)
        {
            if(D_ROBOT_REG_SIZE < nIfInstruction.condition[0].pl_i || 1 > nIfInstruction.condition[0].pl_i)
            {
                programEngine->cmdError(programNum);
                addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            else
            {
                valPList[0] = programSet->regRList[nIfInstruction.condition[0].pl_i - 1];
            }
        }
        else if(DIRECT == nIfInstruction.condition[0].i_addType)
        {
            valPList[0] = nIfInstruction.condition[0].pl_i;
        }
        if(INDIRECT == nIfInstruction.condition[0].j_addType)
        {
            if(D_ROBOT_REG_SIZE < nIfInstruction.condition[0].pl_j || 1 > nIfInstruction.condition[0].pl_j)
            {
                programEngine->cmdError(programNum);
                addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            else
            {
                valPList[1] = programSet->regRList[nIfInstruction.condition[0].pl_j - 1];
            }
        }
        else if(DIRECT == nIfInstruction.condition[0].j_addType)
        {
            valPList[1] = nIfInstruction.condition[0].pl_j;
        }
        if(INDIRECT == nIfInstruction.condition[0].k_addType)
        {
            if(D_ROBOT_REG_SIZE < nIfInstruction.condition[0].pl_k || 1 > nIfInstruction.condition[0].pl_k)
            {
                programEngine->cmdError(programNum);
                addMsg(ENUM_MSG_REMIND,"ProgramEngine","ProgramEngine",3017,robotId);
                return E_PROGRAM_LOOP_RESULT_ERROR;
            }
            else
            {
                valPList[2] = programSet->regRList[nIfInstruction.condition[0].pl_k - 1];
            }
        }
        else if(DIRECT == nIfInstruction.condition[0].k_addType)
        {
            valPList[2] = nIfInstruction.condition[0].pl_k;
        }
//        qDebug() <<"***valPList***"<<valPList;
        break;
    }
    case IF_CONST:
    {

        andValue = nIfInstruction.condition[0].value_i;
//        qDebug() << "andValue="<<andValue;
        break;
    }
    }

//    qDebug() << "operatorType="<<nIfInstruction.condition.at(0).operatorType;
    switch (nIfInstruction.condition.at(0).operatorType)
    {
    case GREATER:
    {
        if(andVar > andValue)
        {
            flag = true;
        }
        break;
    }
    case GREATER_EQU:
    {
//        qDebug()<<"ifInstruction, andVar="<<andVar<<"  andValue="<<andValue;
        if(andVar >= andValue)
        {
            flag = true;
        }
        if(D_POSITIVE_ZERO>andVar && D_NEGATIVE_ZERO<andVar &&
                D_POSITIVE_ZERO>andValue && D_NEGATIVE_ZERO<andValue)// in case of 0.00000000001
        {
            flag = true;
        }
        break;
    }
    case EQU:
    {
//        qDebug()<<"ifInstruction, andVar="<<andVar<<"  andValue="<<andValue;
        if(true == plFlag)
        {
            for(int i = 0; i < 3;i++)
            {
//                qDebug() << "***i*=varPList==valPList***"<<varPList[i]<<valPList[i];
                if((varPList[i] > 500) && (varPList[i] < 10000))
                {
                    if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                    {
                        varPList[i] = valPList[i];
                    }
                    if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                    {
                        varPList[i] = valPList[i];
                    }
                }
                if((varPList[i] > 10000))
                {
                    varPList[i] = valPList[i];
                }

                if((valPList[i] > 500) && (valPList[i] < 10000))
                {
                    if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                    {
                        valPList[i] = varPList[i];
                    }
                    if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                    {
                        valPList[i] = varPList[i];
                    }
                }
                if((valPList[i] > 10000))
                {
                    valPList[i] = varPList[i];
                }
            }
            if(varPList == valPList)
            {
                flag = true;
            }
        }
        else
        {
            if(andVar == andValue)
            {
                flag = true;
            }
            if(D_POSITIVE_ZERO>andVar && D_NEGATIVE_ZERO<andVar &&
                    D_POSITIVE_ZERO>andValue && D_NEGATIVE_ZERO<andValue)// in case of 0.00000000001
            {
                flag = true;
            }
        }
        break;
    }
    case SMALLER_EQU:
    {
        if(andVar <= andValue)
        {
            flag = true;
        }
        if(D_POSITIVE_ZERO>andVar && D_NEGATIVE_ZERO<andVar &&
                D_POSITIVE_ZERO>andValue && D_NEGATIVE_ZERO<andValue)// in case of 0.00000000001
        {
            flag = true;
        }
        break;
    }
    case SMALLER:
    {
        if(andVar < andValue)
        {
            flag = true;
        }
        break;
    }
    case NOT_EQU:
    {
        if(true == plFlag)
        {
            for(int i = 0; i < 3;i++)
            {
                if((varPList[i] > 500) && (varPList[i] < 10000))
                {
                    if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                    {
                        varPList[i] = valPList[i];
                    }
                    if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                    {
                        varPList[i] = valPList[i];
                    }
                }
                if((varPList[i] > 10000))
                {
                    varPList[i] = valPList[i];
                }

                if((valPList[i] > 500) && (valPList[i] < 10000))
                {
                    if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                    {
                        valPList[i] = varPList[i];
                    }
                    if((1 == varPList[i] % 2) && (1 == valPList[i] % 2))
                    {
                        valPList[i] = varPList[i];
                    }
                }
                if((valPList[i] > 10000))
                {
                    valPList[i] = varPList[i];
                }
            }
            if(varPList != valPList)
            {
                flag = true;
            }
        }
        else
        {
            if(andVar != andValue)
            {
                flag = true;
            }
        }
        break;
    }
    }

    if(flag == false)
    {
        programEngine->calculateNextLineToRun(programNum);
    }
    else
    {
        if(programNum >= programSet->size())
        {
            return E_PROGRAM_LOOP_RESULT_ERROR;
        }
        else if(0==(*programSet)[programNum].size() )
        {
            qDebug()<<"caseNeither jump call error2,0==(*programSet)[programNum].size ";
            return E_PROGRAM_LOOP_RESULT_ERROR;
        }
        switch(nIfInstruction.processType)
        {
        case JMP:
        {
//            qDebug()<<"if jmp,,,,";
            QString tmpjumpLabel=(*programSet)[programNum].at(runningLineFloat).ifIns.jumpProcess.jumpLabelStr;
            programEngine->startJump(programNum,tmpjumpLabel);
            break;
        }
        case CALLING:
        {

            programEngine->startCall(programNum,(*programSet)[programNum].at(runningLineFloat).ifIns.callProcess.programName);
//            for(int k = 0; k < programSet->size();k++)
//            {
//                if(programSet[programNum].at(pCount).ifIns.callProcess.programName == programSet[k].programName)
//                {
//                    //                        startCall(programNum,k);
//                    break;
//                }
//            }
            break;
        }
        }
    }

    endFlag = programEngine->isTheLastInstruction(programNum);

    return endFlag;
}


int IfInstructionLogic::plRegStruct2List(int regPlNum)
{
    programSet->plList[regPlNum][0] = programSet->regPlList[regPlNum].row;
    programSet->plList[regPlNum][1] = programSet->regPlList[regPlNum].col;
    programSet->plList[regPlNum][2] = programSet->regPlList[regPlNum].layer;
    return 1;
}


void IfInstructionLogic::addMsg(int messageLevel, string componentName, string messageType,
                           int messageCode, int robotId,
                           int parameter1, int parameter2, int parameter3, int parameter4,QString message)
{
    Message tmpMsg;
    tmpMsg.MessageLevel = messageLevel;
    tmpMsg.componentClassName = componentName;
    tmpMsg.messageType = messageType;
    tmpMsg.robotId = robotId;
    tmpMsg.messageCode = messageCode;
   // tmpMsg.time = t1.tv_sec;


    QString infomationStr;

    switch(messageCode)
    {

    case 3005:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr("; %1,第%2行， IO号超出已有逻辑ＩＯ范围，请检查指令或ＩＯ配置，").arg(message).arg(parameter3)
                +QString::number(parameter1) + ">="
        +QString::number(parameter2);
        break;


    }
    case 3017:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotId);
        infomationStr = infomationStr + QObject::tr(",寄存器指令错误，寄存器的范围超过限定的最大范围，请修改")+message;
    }
        break;



    default:
    {

    }
    }


    tmpMsg.MessageInformation = infomationStr.toStdString();

    // qDebug()<<"53444444444444444444444"<< tmpMsg.messageCode;
    MessageLog::getInstance()->addMessage(tmpMsg);
}

